//
//  ExchangeItemCell.swift
//  MT
//
//  Created by 陈悦 on 2020/5/16.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class ExchangeItemCell: UICollectionViewCell {
    
//    var model: MineWithdrawModel {
//        didSet {
//            guard let model = model else { return }
//            ticketLab.text = "\(model.money)礼券"
//            dimondLab.text = "\(model.ticketAmount)"
//        }
//    }
    
    var model: MineWithdrawModel? {
        didSet {
            if model != nil {
                ticketLab.text = "\(model?.money ?? 0)礼券"
                dimondLab.text = "\(model?.ticketAmount ?? 0)"
                contentView.layer.borderColor = model!.isSelected ? UIColor.theme.main.cgColor : UIColor(hex:0x9b9b9b).cgColor
                selectedIcon.isHidden = !model!.isSelected
            }
        }
    }
    
    
//    @IBOutlet weak var bgView: UIView!
//    @IBOutlet weak var dimondLab: UILabel!
//    @IBOutlet weak var ticketLab: UILabel!
//    @IBOutlet weak var content: UIView!
    
    lazy var dimondLab: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.text.x1d1a1a
        label.font = PingFangSCSemiboldFont(20)
        label.textAlignment = .right
        return label
    }()
    
    lazy var ticketLab: UILabel = {
        let label = UILabel()
        label.textColor = UIColor.text.x1d1a1a
        label.font = PingFangSCRegularFont(14)
        label.textAlignment = .center
        return label
    }()
    
    lazy var dimondIcon: UIImageView = {
        let icon = UIImageView()
        icon.image = UIImage(named: "dimond")
        return icon
    }()
    
    lazy var selectedIcon: UIImageView = {
        let icon = UIImageView()
        icon.image = UIImage(named: "money-selected")
        return icon
    }()
    
    class func reuseIdentity() -> String {
        return "ExchangeItemCellID"
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.layer.cornerRadius = 4
        contentView.layer.borderWidth = 1
        contentView.layer.borderColor = UIColor(hex:0x9b9b9b).cgColor
        setup()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

}

extension ExchangeItemCell {
    private func setup() {
        contentView.addSubview(dimondLab)
        contentView.addSubview(dimondIcon)
        contentView.addSubview(ticketLab)
        contentView.addSubview(selectedIcon)
        
        dimondLab.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView).offset(-6)
            make.centerY.equalTo(contentView).offset(-10)
        }
        
        dimondIcon.snp.makeConstraints { (make) in
            make.left.equalTo(dimondLab.snp.right).offset(4)
            make.centerY.equalTo(dimondLab)
            make.width.height.equalTo(24)
        }
        
        ticketLab.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView)
            make.centerY.equalTo(contentView).offset(15)
        }
        
        selectedIcon.snp.makeConstraints { (make) in
            make.bottom.right.equalTo(contentView)
            make.width.equalTo(28)
            make.height.equalTo(25)
        }
    }
}
